#include <gtest/gtest.h>
#include "../../common/command.h"
using namespace asce;

void TestFunA()
{
	std::cout<<"Command test fun A"<<std::endl;
}

void TestFunB()
{
	std::cout<<"Command test fun B"<<std::endl;
}

TEST(CommandTest, RegisterTest)
{
	EXPECT_TRUE(Command::Instance().Register("test", TestFunA));
	EXPECT_EQ(1, Command::Instance().size());
}

TEST(CommandTest, RegisterSameCommand)
{
	Command::Instance().Clear();
	EXPECT_TRUE(Command::Instance().Register("Test", TestFunA));
	EXPECT_FALSE(Command::Instance().Register("Test", TestFunA));
}

TEST(CommandTest, RegisterMore)
{
	Command::Instance().Clear();
	EXPECT_TRUE(Command::Instance().Register("Test1", TestFunA));
	EXPECT_TRUE(Command::Instance().Register("Test2", TestFunA));
	EXPECT_TRUE(Command::Instance().Register("Test3", TestFunA));
	
	EXPECT_FALSE(Command::Instance().Register("Test4", TestFunA));
	EXPECT_EQ(Command::Instance().size(), Command::Instance().capacity());
}

TEST(CommandTest, UnRegisterInvalidCommand)
{
	Command::Instance().Clear();
	EXPECT_FALSE(Command::Instance().UnRegister("Test"));
}

TEST(CommandTest, UnRegisterValidCommand)
{
	Command::Instance().Clear();
	EXPECT_TRUE(Command::Instance().Register("Test", TestFunA));
	EXPECT_TRUE(Command::Instance().UnRegister("Test"));
	EXPECT_EQ(0, Command::Instance().size());
}

TEST(CommandTest, FindUnExistCommand)
{
	Command::Instance().Clear();
	EXPECT_FALSE(Command::Instance().Find("Test"));
}

TEST(CommandTest, FindExistCommand)
{
	Command::Instance().Clear();
	EXPECT_TRUE(Command::Instance().Register("Test", TestFunA));
	EXPECT_TRUE(Command::Instance().Find("Test"));
}

TEST(CommandTest, RunUnExistCommand)
{
	Command::Instance().Clear();
	Command::Instance().Run("Test");
}

TEST(CommandTest, RunExistCommand)
{
	Command::Instance().Clear();
	EXPECT_TRUE(Command::Instance().Register("Test", TestFunA));
	Command::Instance().Run("Test");
}

int main(int argc, char** argv)
{
	testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}
